<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>oojs封装</title>
    <link rel="stylesheet" href="./style/common.css">
    <script src="js02_oojs_02.js" async></script>
</head>
<body>
    <h1>oojs封装</h1>
    <p class="msg"></p>
    <script>
        document.addEventListener("DOMContentLoaded",function(){
            let msg = document.querySelector(".msg");
            let stu1 = new Student("张三",20);
            msg.innerHTML += stu1.sayHello();
            msg.innerHTML += "<br>";
            stu1.name ="ls";
            msg.age=12;
            msg.innerHTML += stu1.sayHello();
            msg.innerHTML += "<br>";
            stu1.setAge(22);
            msg.innerHTML+= stu1.sayHello();
            msg.innerHTML+= "<br>";

            let stu2= new Student2("ww");
            msg.innerHTML += stu2.sayHello();
            console.log(stu2[SymbolAge]);
            console.log(Object.keys(stu2));
            msg.innerHTML+= "<br>";

            stu2.setAge(23);
            nsg.innerHTML += stu2.sayHello();
            msg.innerHTML+= "<br>";
            let stu3 =new Student2("zy");
            try{
                stu3.setAge(-1);
            }catch(e){
                msg.innerHTML+= '<span class="danger">${e}<span>';
            }

            Student.prototype.test=function(){
                console.log("原型链会自动更新");
            }
            stu1.test();
        });
    </script>
</body>
</html>